package com.cz.order.service.impl;

import com.cz.order.feign.PayFeignClient;
import com.cz.order.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

/**
 * <p>订单服务接口实现</p>
 * <pre>
 * @author gitamacai
 * @date 2019/12/10 14:14
 * </pre>
 */
@Service
public class OrderServiceImpl implements IOrderService {
    @Autowired
    private PayFeignClient payFeignClient;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Override
    public void create(String userId, String commodityCode, Integer count) {
        int orderMoney = count * 100;
        jdbcTemplate.update("insert order_tbl(user_id,commodity_code,count,money) values(?,?,?,?)",
                new Object[] {userId, commodityCode, count, orderMoney});

        payFeignClient.reduce(userId, orderMoney);
    }
}
